package com.taobao.top
{
	import flash.events.Event;

	public class TOPTaoBaoKe
	{
		public function TOPTaoBaoKe()
		{
		}

		public function getTaoBaoKeItemsByKeyword(fields:Array, 
		pid:String, 
		keyword:String="", 
		cid:String="", 
		start_price:String="", 
		end_price:String="", 
		auto_send:Boolean="",
		area:String="",
		start_credit:String="",
		end_credit:String="", 
		sort:String="", 
		is_guarantee:Boolean=true, 
		start_commission:String="", 
		end_commission:String="", 
		start_commissionRate:String="", 
		end_commissionRate:String="", 
		start_commissionNum:String="", 
		end_commissionNum:String="", 
		page_no:String=1, 
		page_size:String=40):void
		{
			var topURLLdr:TOPURLLoader=new TOPURLLoader();
			var reqParamArr:Array=new Array();
			reqParamArr=[new TopRequestParam("method", "taobao.taobaoke.items.get"), 
			new TopRequestParam("fields", TOPUtil.StringArrayToStringWidthComma(fields)), 
			new TopRequestParam("pid", pid),
			new TopRequestParam("auto_send",auto_send),
			new TopRequestParam("page_no",page_no.toString()),
			new TopRequestParam("page_size",page_size.toString())
			];

			if (keyword != "")
			{
				reqParamArr.push(new TopRequestParam("keyword", keyword));
			}

			if (cid != "")
			{
				reqParamArr.push(new TopRequestParam("cid", cid));
			}
			
			if (start_price != "")
			{
				reqParamArr.push(new TopRequestParam("start_price", start_price));
			}
			
			if (end_price != "")
			{
				reqParamArr.push(new TopRequestParam("end_price", end_price));
			}
			
			if (area != "")
			{
				reqParamArr.push(new TopRequestParam("area", area));
			}
			
			if (start_credit != "")
			{
				reqParamArr.push(new TopRequestParam("start_credit", start_credit));
			}
			
			if (end_credit != "")
			{
				reqParamArr.push(new TopRequestParam("end_credit", end_credit));
			}
			
			if (sort != "")
			{
				reqParamArr.push(new TopRequestParam("sort", cid));
			}
			
			if (is_guarantee != "")
			{
				reqParamArr.push(new TopRequestParam("is_guarantee", is_guarantee));
			}
			if (start_commission != "")
			{
				reqParamArr.push(new TopRequestParam("start_commission", start_commission));
			}
			if (end_commission != "")
			{
				reqParamArr.push(new TopRequestParam("end_commission", end_commission));
			}
			if (start_commissionRate != "")
			{
				reqParamArr.push(new TopRequestParam("start_commissionRate", start_commissionRate));
			}
			if (end_commissionRate != "")
			{
				reqParamArr.push(new TopRequestParam("end_commissionRate", end_commissionRate));
			}
			if (start_commissionNum != "")
			{
				reqParamArr.push(new TopRequestParam("start_commissionNum", start_commissionNum));
			}
			
			if (end_commissionNum != "")
			{
				reqParamArr.push(new TopRequestParam("end_commissionNum", end_commissionNum));
			}
			
			topURLLdr.addEventListener(Event.COMPLETE, taobaokeItemsGetHandler);
			topURLLdr.loadData(reqParamArr);
		}

		public function convertTaoBaoKeItems():void
		{
			
		}

		public function convertTaoBaoKeShops():void
		{

		}

		public function getTaoBaoKeListURL():void
		{

		}

		public function getTaoBaoKeReport():void
		{

		}

		private function taobaokeItemsGetHandler(event:Event):void
		{
			switch (event.type)
			{
				case Event.COMPLETE:
					var userArr:Array=taoBaoKeItemsGetJsonParser(event.target.data);
					break;
				default:
					dispatchEvent(event.clone());
					break;
			}
		}

		private function taoBaoKeItemsGetJsonParser(jsonStr:String):void
		{
			if (TOPError.isError(jsonStr))
			{
				var topError:TOPError=TOPError.parseError(jsonStr);
					//dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,
			}
			else
			{
				return objToTaoBaoKeGetResult((JSON.decode(jsonStr) as Object).rsp);
			}
			return null;
		}

		private function objToTaoBaoKeGetResult(itemsObj:Object):void
		{

		}
	}
}